package com.demo.commons;

import ch.qos.logback.core.rolling.RollingFileAppender;

import java.net.InetAddress;

/**
 * Created by Administrator on 2016/11/24.
 */
public class LogbackMachine<E> extends RollingFileAppender<E> {
    public LogbackMachine() {
    }

    public void setFile(String file) {
        if (file != null) {
            String hostName = this.getHostName();
            file = file.replace("#machineName", hostName);
        }

        super.setFile(file);
    }

    private String getHostName() {
        String hostName = "";

        try {
            InetAddress e = InetAddress.getLocalHost();
            String ip = e.getHostAddress().toString();
            hostName = e.getHostName().toString();
        } catch (Exception var4) {
            hostName = "unKnowHostName";
        }

        return hostName;
    }
}
